{
 "cells": [
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-15T13:03:20.981009Z",
     "start_time": "2025-06-15T13:03:20.976112Z"
    }
   },
   "cell_type": "code",
   "source": "from sentence_transformers import SentenceTransformer",
   "id": "8192a08d18b70bf4",
   "outputs": [],
   "execution_count": 9
  },
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-06-15T13:06:03.750372Z",
     "start_time": "2025-06-15T13:06:03.372651Z"
    }
   },
   "source": [
    "# 加载模型\n",
    "model = SentenceTransformer(r'E:\\python\\sbert-base-chinese-nli')\n",
    "\n",
    "# 输入中文句子\n",
    "sentences = [\n",
    "    '我喜欢自然语言处理',\n",
    "    '我热爱人工智能技术',\n",
    "    '这是一个测试句子'\n",
    "]\n",
    "\n",
    "# 获取句子嵌入（向量）\n",
    "embeddings = model.encode(sentences)\n",
    "\n",
    "# 打印结果\n",
    "for s, e in zip(sentences, embeddings):\n",
    "    print(f\"Sentence: {s}\")\n",
    "    print(f\"Embedding: {e[:10]}...\")  # 只显示前10维作为示例\n",
    "    print()"
   ],
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "No sentence-transformers model found with name E:\\python\\sbert-base-chinese-nli. Creating a new one with mean pooling.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Sentence: 我喜欢自然语言处理\n",
      "Embedding: [-0.03340906  0.7195306   0.6317454   0.5621097  -0.59622437  0.1908557\n",
      "  0.76581806 -0.27913225 -0.5054835  -0.7198133 ]...\n",
      "\n",
      "Sentence: 我热爱人工智能技术\n",
      "Embedding: [ 0.09741951 -0.22417186  0.26396596  1.0736562  -0.5590536  -0.5201331\n",
      " -0.07095028 -1.6944588  -0.22935252 -0.17968386]...\n",
      "\n",
      "Sentence: 这是一个测试句子\n",
      "Embedding: [ 0.49681368  0.03238125  0.6043497   0.36379054  0.27704617 -1.0285702\n",
      " -0.86716443 -0.808987    0.29960793 -0.06101848]...\n",
      "\n"
     ]
    }
   ],
   "execution_count": 11
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
